package Day008_List_Collections_set.ZuoYe;

import java.util.HashSet;
import java.util.Iterator;

public class Test2 {
    public static void main(String[] args) {

        HashSet<String> set = new HashSet<>();
        String[] str = {"刘备","关羽","张飞","刘备","张飞"};
        for (int i = 0; i < str.length; i++) {
            set.add(str[i]);
        }
        System.out.println(set.size()); // 3

        //迭代器遍历
        Iterator<String> it = set.iterator();
        while (it.hasNext()){
            String s = it.next();
            System.out.print(s + " "); //关羽 张飞 刘备
        }
        System.out.println();
        //增强for
        for (String s : set) {
            System.out.print(s + " "); //关羽 张飞 刘备
        }
    }
}
